package com.hserver.test;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.ExecCreateCmdResponse;
import com.github.dockerjava.api.model.*;
import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.core.DockerClientBuilder;
import com.github.dockerjava.core.DockerClientConfig;
import com.github.dockerjava.core.command.ExecStartResultCallback;
import com.github.dockerjava.netty.NettyDockerCmdExecFactory;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

public class InitSwarmDockerExec {

    public static void main(String[] args) throws InterruptedException, UnsupportedEncodingException {


        DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
//                .withDockerHost("tcp://*.103.218.193:9393")
//                .withDockerHost("tcp://*.106.83.31:9393")
                .build();

        NettyDockerCmdExecFactory factory = new NettyDockerCmdExecFactory();

        DockerClient dockerClient = DockerClientBuilder.getInstance(config)
                .withDockerCmdExecFactory(factory)
                .build();
//        SwarmSpec swarmSpec = new SwarmSpec()
//                .withName("default")
//                .withDispatcher(new SwarmDispatcherConfig()
//                        .withHeartbeatPeriod(10000000L)
//                ).withOrchestration(new SwarmOrchestration()
//                        .withTaskHistoryRententionLimit(100)
//                ).withCaConfig(new SwarmCAConfig()
//                        .withNodeCertExpiry(60 * 60 * 1000000000L /*ns */))
//                .withRaft(new SwarmRaftConfig()
//                        .withElectionTick(8)
//                        .withSnapshotInterval(20000)
//                        .withHeartbeatTick(5)
//                        .withLogEntriesForSlowFollowers(200)
//                ).withTaskDefaults(new TaskDefaults());
//
//        dockerClient.initializeSwarmCmd(swarmSpec)
//                .withListenAddr("127.0.0.1")
//                .withAdvertiseAddr("127.0.0.1")
//                .exec();
//        System.out.println(swarmSpec.toString());

        try {
            Swarm swarm = dockerClient.inspectSwarmCmd().exec();
            System.out.println(swarm);
        }catch (Throwable e){
//            e.printStackTrace();
        }



    }


}
